# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=accesskit-c
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.15.1
pkgrel=1
pkgdesc="Accessibility infrastructure for UI toolkits - C bindings (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://accesskit.dev'
msys2_repository_url='https://github.com/AccessKit/accesskit-c'
license=('spdx:Apache-2.0 OR MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-rust"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "git"
)
source=("accesskit-c-${pkgver}::git+https://github.com/AccessKit/accesskit-c#tag=${pkgver}"
        "0001-fix-rust-clang-target.patch")
sha256sums=('197d7f7e3c9fd8fd28cb9c07ad29f44f75ffe6812934216f405635f6e82f5207'
            'c5fb49a2589dab8dde32521ba0ffb7bb7ef78ab32aa763b6a4274b490949c6aa')

prepare() {
  cd "${_realname}-${pkgver}"

  # same as https://gitlab.gnome.org/GNOME/librsvg/-/commit/22086fb38b9709116cced919fbd0ec0c7a828a6c
  patch -p1 -i "${srcdir}/0001-fix-rust-clang-target.patch"
}

build() {
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      "build-${MSYSTEM}" \
      "${_realname}-${pkgver}"

  meson compile -C "build-${MSYSTEM}"
}

package() {
  meson install -C "build-${MSYSTEM}" --destdir "${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE-MIT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE-APACHE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-APACHE"
}
